<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	public function index() {
            $this->load->view('login/index');
	}

        public function validate() {
            $emailAddress = $this->input->post('emailAddress');
            $password = $this->input->post('password');

            if($emailAddress == 'pim@duijst.nl' && $password == 'jemoeder') {
                $this->session->set_userdata('isLoggedIn', TRUE);
                $this->session->set_userdata('userName', 'Pim Duijst');
                redirect('portal');
            }
            elseif(!$emailAddress || !$password) {
                $this->session->set_flashdata('error','Please fill in all required fields.');
                redirect('login');
            }
            else {
                $this->session->set_flashdata('error','Username or password incorrect.');
                redirect('login');
            }
        }

        public function destroy() {
            $this->session->sess_destroy();
            redirect('login');
        }
}